﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace devicesDll //Data Storage Classes, few functional parts
{

    public struct IpVlan
    {
        public IpVlan(IPAddress ip, int vlan)
        {
            Ip = ip;
            Vlan = vlan;
        }

        public IPAddress Ip;
        public int Vlan;
    }

    public class SingleQuery
    {
        #region Variables
        private string queryString;
        private bool switchOnly;
        private Device currentDevice;
        #endregion

        #region Constructor
        public SingleQuery(Device dev, bool swOnly, string qu)
        {
            currentDevice = dev;
            switchOnly = swOnly;
            queryString = qu;
        }
        #endregion

        #region Properties
        public Device CurrentDevice
        {
            get { return currentDevice; }
            set { currentDevice = value; }
        }
        
        public bool SwitchOnly
        {
            get { return switchOnly; }
            set { switchOnly = value; }
        }
        
        public string QueryString
        {
            get { return queryString; }
            set { queryString = value; }
        }
        #endregion
    }

    public class CustomResult
    {
        #region Variables
        string varName;
        object result;
        bool errorOccurred;
        string errorQuery;
        string errorMessage;
        #endregion

        #region Constructor
        public CustomResult(string varName, object result)
        {
            this.varName = varName;
            this.result = result;
            errorOccurred = false;
        }

        public CustomResult(string errorQuery, string errorMessage)
        {
            errorOccurred = true;
            this.errorQuery = errorQuery;
            this.errorMessage = errorMessage;
        }
        #endregion

        #region Properties
        public string VariableName { get { return varName; } }
        public object Result { get { return result; } }
        public bool ErrorOccurred { get { return errorOccurred; } }
        public string ErrorQuery { get { return errorQuery; } }
        public string ErrorMessage { get { return errorMessage; } }
        
        #endregion
    }

    public class PrinterCommands
    {
        string[][] oid = new string[][] { 
                new string[] { "Toner", "1.3.6.1.2.1.43.11.1.1.6.1.1" }, 
                new string[] { "SerialNumber","1.3.6.1.2.1.43.5.1.1.17.1"},
                new string[] { "State","1.3.6.1.2.1.43.16.5.1.2.1.1"},
                new string[] { "LifeCount","1.3.6.1.2.1.43.10.2.1.4.1.1"},
                new string[] { "SupplyMaximum","1.3.6.1.2.1.43.11.1.1.8.1.1"},
                new string[] { "SupplyLevel","1.3.6.1.2.1.43.11.1.1.9.1.1"},
                new string[] { "InputDescription","1.3.6.1.2.1.43.8.2.1.18"},
                new string[] { "PaperMax","1.3.6.1.2.1.43.8.2.1.9"},
                new string[] { "PaperCurrentLevel","1.3.6.1.2.1.43.8.2.1.10"}
                                        };

        #region methods
        public string this[string objektIdentifier]
        {
            get
            {
                foreach (string[] item in oid)
                {
                    if (item[0] == objektIdentifier)
                    {
                        return item[1];
                    }
                }
                return null;
            }
        }
        #endregion
    }

    public class SwitchCommands
    {
        string[][] oid = new string[][]{
                new string[] {"MacAddressList", "1.3.6.1.2.1.17.4.3.1.1"},
                new string[] {"FirstBridgeList","1.3.6.1.2.1.17.4.3.1.2"},
                new string[] {"SeconBridgeList","1.3.6.1.2.1.17.1.4.1.2"},
                new string[] {"Portlist",       "1.3.6.1.2.1.31.1.1.1.1"},
                new string[] {"TrunkList",      "1.3.6.1.4.1.9.9.46.1.6.1.1.14"}
                                        };

        #region Methods
        public string this[string objektIdentifier]
        {
            get
            {
                foreach (string[] item in oid)
                {
                    if (item[0] == objektIdentifier)
                    {
                        return item[1];
                    } 
                }
                return null;
            }
        }
        #endregion
    }

    public class IdentifyDeviceCommands
    {
        string[][] oid = new string[][] { new string[] { "StandardRequest", "1.3.6.1.2.1.1.1.0" } };

        #region Methods
        public string this[string objektIdentifier]
        {
            get
            {
                foreach (string[] item in oid)
                {
                    if (item[0] == objektIdentifier)
                    {
                        return item[1];
                    }
                }
                return null;
            }
        }
        #endregion

    }

    public class CustomQuery
    {
        private string query;
        private DeviceType group;

        public CustomQuery(string query, string group)
        {
            this.group = (DeviceType)Enum.Parse(typeof(DeviceType), group, true);
            this.query = query;
        }

        public string Query
        {
            get { return query; }
            set { query = value; }
        }

        public DeviceType Group
        {
            get { return group; }
            set { group = value; }
        }   
    }

    [Flags]
    public enum QueryProgress { None = 0, SwitchSuccessfull = 0x01, DHCPSuccessfull = 0x02, DataBaseSuccessfull = 0x04, DeviceQueriesSuccessfull = 0x08, DataBaseUpdateSuccessfull = 0x10, CompleteSuccessfull = 0x1F, SwitchWarning = 0x20, SwitchError = 0x40, DHCPError = 0x80 }

    public enum DeviceType {Device = 0, PC, Printer, unreachableDevice }
}
